﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using soho.Library;
using System.IO;

public partial class CRMSignUp : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {

        }
        else
        {
            lblError.Text = "";
        }
    }
    protected void btnSignUp_Click(object sender, EventArgs e)
    {
        //

        Customer customer = CustomerUtl.GetCustomer(txtUserName.Text.Trim());
        if (customer != null)
        {
            lblError.Text = GetLocalResourceObject("lblError.Text.UserNameExists").ToString();
        }
        else
        {
            customer = new Customer();
            customer.UserName = txtUserName.Text.Trim();
            customer.Password = sohoUtility.EncodePassword(txtPassword.Text.Trim());
            customer.FullName = txtFullName.Text.Trim();
            customer.CompanyName = txtCompanyName.Text.Trim();
            customer.Address = txtAddress.Text.Trim();
            customer.PhoneNumber = txtPhoneNumber.Text.Trim();
            customer.Email = txtEmail.Text.Trim();

            try
            {
                CustomerUtl.Insert(customer);

                string path = System.IO.Path.Combine(Request.PhysicalApplicationPath, @"CustomerFiles\" + customer.UserName);
                Directory.CreateDirectory(path);
            }
            catch(Exception ex)
            {
                lblError.Text = GetLocalResourceObject("lblError.Text.Error").ToString();
                
                return;
            }

            lblError.Text = GetLocalResourceObject("lblError.Text.Success").ToString();
        }
    }
}